<template>
  <view class="login-page">
    <!-- Logo -->
    <view class="logo-wrap">
      <image class="logo" src="https://aixue-1256834579.cos.ap-shanghai.myqcloud.com/1761806399NQEqc76.png" mode="widthFix"></image>
      <text class="title">超吉车员工OA登录</text>
    </view>

    <!-- 输入框 -->
    <view class="form-wrap">
      <input
        class="input"
        type="text"
        v-model="username"
        placeholder="请输入用户名"
        placeholder-class="placeholder" @input="onKeyEvent($event,'username')"
      />
      <input
        class="input"
        type="password"
        v-model="password"
        placeholder="请输入密码"
        placeholder-class="placeholder" @input="onKeyEvent($event,'password')"
      />

      <!-- 登录按钮 -->
      <button class="login-btn" @tap="login">登录</button>
    </view>
  </view>
</template>

<script>
import common_config from '../../static/js/common.js';
var config = common_config.config;
var access_token = uni.getStorageSync('access_token');
var that;	
var userInfo;
export default {
  data() {
    return {
      username: '',
      password: ''
    };
  },
  onLoad() {
		that = this;
  },
  methods: {
    login() {
      if (!this.username || !this.password) {
        uni.showToast({ title: '请输入账号和密码', icon: 'none' });
        return;
      }
      uni.showLoading({ title: '登录中...' });
     uni.request({
     	url: config.request_url+'/index/user_manage/sub_login',
     	data: {
     		username:that.username,
			password:that.password
     	},
     	method: 'POST',
     	header: {
     	     "Content-Type": "application/x-www-form-urlencoded"
     	},
     	success: (res) => {
			uni.hideLoading();
     		res = res.data;
     		if(res.code != 200){
				common_config.calert(res.msg);
			}else{
				var userInfo = JSON.stringify(res.data);
				uni.setStorageSync('userInfo',userInfo);
				uni.switchTab({
					url:'/pages/index/yewu'
				});
			}
     	}
     });
    },
	//表单输入事件
	onKeyEvent:function(event,the_id){
		that[the_id] = event.target.value;
	}
  }
};
</script>

<style scoped>
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #f5f6fa;
  padding: 60rpx 40rpx;
  box-sizing: border-box;
}

/* Logo区域 */
.logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 80rpx;
}
.logo {
  width: 200rpx;
  height: auto;
  border-radius: 20rpx;
}
.title {
  margin-top: 20rpx;
  font-size: 32rpx;
  color: #333;
  font-weight: 600;
  letter-spacing: 2rpx;
}

/* 表单 */
.form-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 30rpx;
}
.input {
  width: 100%;
  height: 90rpx;
  border-radius: 45rpx;
  background: #fff;
  padding: 0 40rpx;
  font-size: 30rpx;
  box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.05);
  box-sizing: border-box;
}
.placeholder {
  color: #bbb;
  font-size: 28rpx;
}

/* 按钮 */
.login-btn {
  width: 100%;
  height: 90rpx;
  border-radius: 45rpx;
  background: linear-gradient(135deg, #007aff, #0099ff);
  color: #fff;
  font-size: 32rpx;
  font-weight: 500;
  text-align: center;
  line-height: 90rpx;
  margin-top: 40rpx;
  box-shadow: 0 8rpx 16rpx rgba(0, 122, 255, 0.3);
}
.login-btn:active {
  opacity: 0.85;
}
</style>
